<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>入库申请登记复核</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link rel="stylesheet" href="../../../lib/layui-v2.5.5/css/layui.css" media="all">
	</head>
	<body>
		<div>
			<div style="margin-left: 5%;margin-top: 1%;">
				<div style="display: inline-block;margin-left: 0%;">
					<div style="display: inline-block;">
						<label>入库编号：</label>
					</div>
					<div style="display: inline-block;">
						<input class="layui-input" id="name" type="text" />
					</div>
					<div style="display: inline-block;" class="layui-btn-group demoTable">
						<button class="layui-btn" data-type="namesel">查询</button>
					</div>
				</div>
				<div style="display: inline-block;" class="layui-btn-group demoTable">
					<button class="layui-btn layui-btn-sm" lay-event="butg" data-type="piltg">批量审核通过</button>
					<button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="tg" data-type="pilbutg">批量审核不通过</button>
				</div>
			</div>
			<table id="demo" lay-filter="test"></table>
			<div class="layui-row" id="update" style="display:none;">
				<div class="layui-col-md10" align="center" style="width: 100%;">
					<form class="layui-form layui-from-pane" style="margin-top: 20px;" method="" id="accountFomat">
						<div style="text-align: left;">
							入库人：&nbsp;&nbsp;<label id="labelname" style="margin-right: 5%;"></label>
							入库理由：&nbsp;&nbsp;<label id="labelreason"></label>
						</div>
						<table id="table" lay-filter="table"></table>
						<div class="layui-form-item" style="margin-top:40px">
							总件数：&nbsp;&nbsp;<label id="labelnumber" style="margin-right: 5%;"></label>
							总金额：&nbsp;&nbsp;<label id="labelprice"></label>
						</div>
					</form>
				</div>
			</div>
		</div>
	</body>

	<script src="../../../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
	<script src="../../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
	<script src="../../../lib/common/jquery.cookie.min.js" charset="utf-8"></script>
	<script src="../../../lib/common/common.js" charset="utf-8"></script>
	<script type="text/javascript">
		layui.use(["form", "table", 'jquery', 'laydate'], function() {
			var table = layui.table,
				layer = layui.layer,
				form = layui.form,
				laydate = layui.laydate,
				$ = layui.jquery;
			table.render({
				elem: '#demo',
				id: 'idTest',
				url: api8 + "PutRepertory/PutRepertorychecker",
				cols: [
					[ //标题栏
						{
							checkbox: true
						}, {
							field: 'gatherId',
							title: '订单编号'
						}, {
							field: 'storer',
							title: '入库人'
						}, {
							field: 'reason',
							title: '入库理由',
							templet: '#reason'
						}, {
							field: 'registerTime',
							title: '登记时间'
						}, {
							field: 'amountSum',
							title: '总件数'
						}, {
							field: 'costPriceSum',
							title: '总金额'
						}, {
							field: '',
							title: '操作',
							templet: '#formulate',
							width: 260
						}
					]
				]
			});
			table.on('checkbox(test)', function(obj) {
			});

			function ajax(url, type, data) {
				$.ajax({
					url: api8 + url,
					type: type,
					data: data,
					dataType: "JSON",
					contentType: 'application/json;charset=utf-8',
					success: function(data) {
						layer.msg("执行成功！", {
							icon: 1
						})
						return true;
					},
					error: function(data) {
						console.log(data.status);
					}
				});
			}
			//批量审核
			var $ = layui.$,
				active = {
					pilbutg: function() { //获取选中数据
						layer.confirm('是否审核不通过的记录', function(index) {
							var arr = []; //不通过
							var checkStatus = table.checkStatus('idTest'),
								data = checkStatus.data;
							for (var i = 0; i < data.length; i++) {
								arr[i] = data[i].id
							}
							ajax("PutRepertory/PutRepertoryupdate?check=S001-2&id=" + arr, "Post", {
								'check': "S001-2",
								'id': data.id
							})
						});
					},
					piltg: function() { //获取选中数据
						//通过

						layer.confirm('是否审核通过的记录', function(index) {
							var checkStatus = table.checkStatus('idTest'),
								data = checkStatus.data;
							var arr = [];
							for (var i = 0; i < data.length; i++) {
								arr[i] = data[i].id
							}
							ajax("PutRepertory/PutRepertoryupdate?check=S001-1&id=" + arr, "Post", {
								'check': "S001-1",
								'id': data.id
							})
						});
					},
					namesel: function() { //获取选中数目
						table.render({
							elem: '#demo',
							id: 'idTest',
							url: api8 + "PutRepertory/PutRepertorychecker?name=" + $("#name").val(),
							cols: [
								[ //标题栏
									{
										checkbox: true
									}, {
										field: 'gatherId',
										title: '订单编号'
									}, {
										field: 'storer',
										title: '入库人'
									}, {
										field: 'reason',
										title: '入库理由',
										templet: '#reason'
									}, {
										field: 'registerTime',
										title: '登记时间'
									}, {
										field: 'amountSum',
										title: '总件数'
									}, {
										field: 'costPriceSum',
										title: '总金额'
									}, {
										field: '',
										title: '操作',
										templet: '#formulate',
										width: 260
									}
								]
							]
						});
					},
					msg: function() { //验证是否全选

					}
				};
			//批量审核
			$('.demoTable .layui-btn').on('click', function() {
				var type = $(this).data('type');
				active[type] ? active[type].call(this) : '';
			});
			table.on('tool(test)', function(obj) {
				var putr = new Array();
				var data = obj.data;
				putr.push(data);
				if (obj.event === 'detail') {
					layer.open({
						type: 1,
						title: '查看详情',
						area: ['900px', '600px'],
						content: $('#update') //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
					});
					console.log(data.reason)
					if (data.reason == "R001-1") {
						$("#labelreason").html("生产入库")
					} else if (data.reason == "R001-2") {
						$("#labelreason").html("库存初始")
					} else if (data.reason == "R001-3") {
						$("#labelreason").html("赠送")
					} else if (data.reason == "R001-4") {
						$("#labelreason").html("内部归还")
					}
					$("#labelname").html(data.storer)
					$("#labelnumber").html(data.amountSum)
					$("#labelprice").html(data.costPriceSum)
					table.init('table', {
						url: api8 + "PutRepertoryDetails/PutRepertoryDetailsid?id=" + data.id,
						cols: [
							[{
								field: 'productId',
								title: '产品编号'
							}, {
								field: 'productName',
								title: '物料名称'
							}, {
								field: 'productDescribe',
								title: '描述'
							}, {
								field: 'amount',
								title: '数量',
								edit: 'text'
							}, {
								field: 'amountUnit',
								title: '单位',
							}, {
								field: 'costPrice',
								title: '	成本单价（元）',
							}, {
								field: 'subtotal',
								title: '	小计（元）',
							}]
						]
					});
				} else if (obj.event === 'del') {
					layer.confirm('是否确认不审核通过', function(index) {
						var arr=[];
							arr[0] = data.id;
						ajax("PutRepertory/PutRepertoryupdate?check=S001-2&id=" + arr, "Post", {
							'check': "S001-2",
							'id': data.id
						});
					});
				} else if (obj.event === 'edit') {
					layer.confirm('是否确认审核通过', function(index) {
						var arr = [];
							arr[0] = data.id;
						ajax("PutRepertory/PutRepertoryupdate?check=S001-1&id=" + arr, "Post", {
							'check': "S001-1",
							'id': data.id
						})
					});
				}
			});

		})
	</script>
	<script type="text/html" id="reason">
		{{# if(d.reason=='R001-1'){d.reason='生产入库'}}
						{{d.reason}}
					{{# }else if(d.reason=='R001-2'){d.reason='库存初始'}}
						{{d.reason}}
					{{# }else if(d.reason=='R001-3'){d.reason='赠送'}}
						{{d.reason}}
					{{# }else if(d.reason=='R001-4'){d.reason='内部归还'}}
						{{d.reason}}
					{{# }}}
		
	</script>
	<script type="text/html" id="formulate">
		{{# if(d.reason=='R001-1'){d.reason='生产入库'}}
				<button type="button" lay-event="detail" data-type="msg" class="layui-btn layui-btn-xs">查看详情</button>
				<button type="button" lay-event="edit" class="layui-btn layui-btn-xs">审核通过</button>
					{{# }else{d.reason='其他归还'}}
				<button type="button" lay-event="detail" data-type="msg" class="layui-btn layui-btn-xs">查看详情</button>
				<button type="button" lay-event="edit" class="layui-btn layui-btn-xs">审核通过</button>
				<button type="button" class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del" >审核不通过</button>
			{{# }}}
		
	</script>
</html>
